﻿@model IEnumerable<NavigationItem>
@{
    bool recursive = false;
    if (ViewData["Recursive"] != null)
    {
        recursive = true;
    }
}
@if (this.Model != null && this.Model.Count() > 0)
{
    int idx = 0;
    int total = this.Model.Count();
    <ul>
        @foreach (var item in this.Model)
        {
            if (MenuHelper.CanCurrentUserAccessMenuItem(item))
            {
            <li class="@(MenuHelper.IsSelected(item) ? "selected" : "") @(idx == 0 ? "first" : "") @(idx == total - 1 ? "last" : "")">
                <a href="@item.Url" @(string.IsNullOrEmpty(item.Target) ? "" : Html.Raw(string.Format("target={0}", item.Target)).ToString()) title="@item.Caption">
                    @if (!string.IsNullOrEmpty(item.ImageUrl))
                    {
                        <img src="@Theme.Image(item.ImageUrl)" alt=""/>
                    }
                    <span>@item.Caption</span> </a>
                @if (recursive)
                {
                    ViewDataDictionary viewData = new ViewDataDictionary();
                    viewData.Add("Recursive", true);
                    @Html.Partial("_Menu", item.Items, viewData);
                }
            </li>
                idx++;
            }
        }
    </ul>
}